package cn.moukou.sbzz.service;

import cn.moukou.sbzz.mapper.MetaClassMapper;
import cn.moukou.sbzz.pojo.MetaClass;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class MetaClassService {

    @Autowired
    MetaClassMapper metaClassMapper;

    public int addOneMetaClass(String name, String type) {
        MetaClass metaClass = new MetaClass();
        metaClass.setName(name);
        metaClass.setType(type);
        int cnt = metaClassMapper.insert(metaClass);
        return cnt;
    }

    public List<MetaClass> getMetaClassListByType(String type) {
        if (type.equals("all")) {
           return metaClassMapper.selectList(null);
        }

        QueryWrapper<MetaClass> wrapper = new QueryWrapper<>();
        wrapper.eq("type", type);
        List<MetaClass> metaClassList = metaClassMapper.selectList(wrapper);
        return metaClassList;
    }

    public int updateMetaClassName(String id, String name) {
        MetaClass metaClass = metaClassMapper.selectById(id);
        metaClass.setName(name);
        return metaClassMapper.updateById(metaClass);
    }

    public int deleteMetaClass(String id) {
        int cnt = metaClassMapper.deleteById(id);
        return cnt;
    }
}
